<?php
namespace Biz\model;

use Doraemon\pockets\datebase\BaseDbModel;

class GoodsHeatDegree extends BaseDbModel
{
	const _CONFIG_FILE_ = 'db_shop';

	const _CONFIG_SELECT_ = 'db_shop';

	const _DATABASE_ = 'shop';

	const _TABLE_NAME = 'goods_heat_degree';


	const DEGREE_BASE_BROWSE = 0.007;
	const DEGREE_BASE_FAV = 0.005;
	const DEGREE_BASE_ADD_CART = 0.130;
	const DEGREE_BASE_ORDER = 0.260;


	const ACTION_COUNT_HEAT_MAP = [
		GoodsActionCount::DEGREE_TYPE_BROWSE => GoodsHeatDegree::DEGREE_BASE_BROWSE,
		GoodsActionCount::DEGREE_TYPE_FAV => GoodsHeatDegree::DEGREE_BASE_FAV,
		GoodsActionCount::DEGREE_TYPE_ADD_CART => GoodsHeatDegree::DEGREE_BASE_ADD_CART,
		GoodsActionCount::DEGREE_TYPE_ORDER => GoodsHeatDegree::DEGREE_BASE_ORDER,
	];

	const STAUTS_NORMAL = 1;
	const STAUTS_DEL = 0;

	public static function getCurrentDegree($goodsId)
	{
		$thirtyDateAgo = date('Y-m-d', time() - 30 * 86400);
		$hearDegree = self::get('heat_degree', [
			'goods_id' => $goodsId,
			'status' => self::STAUTS_NORMAL,
			'add_date[>]' => $thirtyDateAgo,
		]);
		if ($hearDegree) {
			return $hearDegree;
		}
		return 0;
	}
}
